<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    *
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @copyright essentialmind.com 2005
    *
    *********************************************************/

    /***
    * @package ajax
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    * @copyright essentialmind.com 2005
    ***/
    class ajaxDeleteTag extends ajaxAction{

        public function process(){
            $pageid = (int)$_REQUEST['pid'];
            $tagid  = (int)$_REQUEST['id'];
            
            $this->db->Execute("DELETE FROM tag_page_map WHERE page_id = $pageid AND tag_id = $tagid");
            
            //now, if this tag still has references, return its name, otherwise - kill it
            if($this->db->getOne("SELECT count(*) FROM tag_page_map WHERE tag_id = $tagid") > 0){
                $this->r->tagName = $this->db->getOne("SELECT name FROM tags WHERE id = $tagid");
            }else{
                $this->db->Execute("DELETE FROM tags WHERE id = $tagid");
            }
        }
    }
?>